<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>订单管理</title>
<!-- 引入css样式文件 -->
<!-- Bootstrap Core CSS -->
<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
<!-- MetisMenu CSS -->
<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
<!-- DataTables CSS -->
<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
<!-- Custom CSS -->
<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
<!-- Custom Fonts -->
<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet"
	type="text/css" />
<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet"
	type="text/css" />
</head>
<body>
	<div id="wrapper">
		<!-- 导航栏部分 -->
		<nav class="navbar navbar-default navbar-static-top" role="navigation"
			style="margin-bottom: 0">
			<div class="navbar-header">
				<a class="navbar-brand" href="<%=basePath%>customer/list.action">客户管理系统</a>
			</div>
			<!-- 导航栏右侧图标部分 -->
			<ul class="nav navbar-top-links navbar-right">
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 系统设置
			</a>
			<ul class="dropdown-menu dropdown-user">
				<li>
					<a href="${pageContext.request.contextPath }/logout.action">
					退出登录
					</a>
				</li>
			</ul> 
		</li>
	</ul>
				<!-- 用户信息和系统设置结束 -->
			</ul>
			<!-- 左侧显示列表部分 start-->
			<div class="navbar-default sidebar" role="navigation">
				<div class="sidebar-nav navbar-collapse">
					<ul class="nav" id="side-menu">
				
				<li>
				    <a href="${pageContext.request.contextPath }/customer/list.action" class="active">
				      客户管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/user/list.action" class="active">
				      用户管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/product/list.action" class="active">
				      产品管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/orders/list.action" class="active">
				      订单管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/project/list.action" class="active">
				      进货管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/basedict/list.action" class="active">
				      数据字典管理
				    </a>
				</li>
			</ul>
				</div>
			</div>
			<!-- 左侧显示列表部分 end-->
		</nav>
		<!-- 客户订单列表查询部分  start-->
		<div id="page-wrapper">
			<div class="row">
				<div class="col-lg-12">
					<h1 class="page-header">订单查询</h1>
				</div>
				<!-- /.col-lg-12 -->
			</div>
			<!-- /.row -->
			<div class="panel panel-default">
				<div class="panel-body">
					<form class="form-inline" method="get"
						action="${pageContext.request.contextPath }/orders/list.action">
						<div class="form-group">
							<label for="ordersNumber">订单编号</label> <input type="text"
								class="form-control" id="ordersNumber" value="${ordersNumber }"
								name="ordersNumber" />
						</div>
						<div class="form-group">
							<label for="cust_id">客户ID</label> <input type="text"
								class="form-control" id="cust_id" value="${cust_id }"
								name="cust_id" />
						</div>
						<button type="submit" class="btn btn-primary">查询</button>
					</form>
				</div>
			</div>
			<a href="#" class="btn btn-primary" data-toggle="modal"
				data-target="#newOrdersDialog" onclick="clearOrders()">新建</a>
			<div class="row">
				<div class="col-lg-12">
					<div class="panel panel-default">
						<div class="panel-heading">订单信息列表</div>
						<!-- /.panel-heading -->
						<table class="table table-bordered table-striped">
							<thead>
								<tr>
									<th>订单ID</th>
									<th>订单编号</th>
									<th>客户ID</th>
									<th>客户名称</th>
									<th>产品编号</th>
									<th>产品名称</th>
									<th>产品价格</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${page.rows}" var="row">
									<tr>
										<td>${row.id}</td>
										<td>${row.number}</td>
										<td>${row.cust_id}</td>
										<td>${row.cust_name}</td>
										<td>${row.product_id}</td>
										<td>
										<c:forEach items="${row.productList}" var="product">
											${product.name}
										</c:forEach>
										</td>
										<td>
										<c:forEach items="${row.productList}" var="product">
											${product.price}
										</c:forEach>
										</td>
										<td> 
											<a href="#" class="btn btn-primary btn-xs" data-toggle="modal"
											data-target="#ordersEditDialog"
											onclick="editOrders(${row.id})">修改</a> <a href="#"
											class="btn btn-danger btn-xs"
											onclick="deleteOrders(${row.id})">删除</a></td>
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
						<div class="col-md-12 text-right">
							<ujn:page
								url="${pageContext.request.contextPath }/orders/list.action" />
						</div>
						<!-- /.panel-body -->
					</div>
					<!-- /.panel -->
				</div>
				<!-- /.col-lg-12 -->
			</div>
		</div>
	</div>
	<!-- 订单列表查询部分  end-->

	<!-- 修改订单模态框 -->
	<div class="modal fade" id="ordersEditDialog" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">修改订单信息</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="edit_orders_form">
						<input type="hidden" id="edit_id" name="id" />
						<div class="form-group">
							<label for="edit_number" class="col-sm-2 control-label">订单编号</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_number"
									placeholder="订单编号" name="number" />
							</div>
						</div>
						<div class="form-group">
							<label for="edit_cust_id" class="col-sm-2 control-label">客户ID</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_cust_id"
									placeholder="客户ID" name="cust_id" />
							</div>
						</div>
						<div class="form-group">
							<label for="edit_cust_name" class="col-sm-2 control-label">客户名称</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_cust_name"
									placeholder="客户名称" name="cust_name" />
							</div>
						</div>
						<div class="form-group">
							<label for="edit_product_id" class="col-sm-2 control-label">产品ID</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_product_id"
									placeholder="产品ID" name="product_id" />
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary"
						onclick="updateOrders()">保存修改</button>
				</div>
			</div>
		</div>
	</div>


	<!-- 创建客户模态框 -->
	<div class="modal fade" id="newOrdersDialog" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">新建订单信息</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="new_orders_form">
						<div class="form-group">
							<label for="new_number" class="col-sm-2 control-label">
								订单编号 </label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="new_number"
									placeholder="订单编号" name="number" />
							</div>
						</div>
						<div class="form-group">
							<label for="new_cust_id" class="col-sm-2 control-label">客户ID</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="new_cust_id"
									placeholder="客户ID" name="cust_id" />
							</div>
						</div>
						<div class="form-group">
							<label for="new_cust_name" class="col-sm-2 control-label">客户名称</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="new_cust_name"
									placeholder="客户名称" name="cust_cust_name" />
							</div>
						</div>
						<div class="form-group">
							<label for="new_product_id" class="col-sm-2 control-label">产品ID</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="new_product_id"
									placeholder="产品ID" name="product_id" />
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary"
						onclick="createOrders()">创建订单</button>
				</div>
			</div>
		</div>
	</div>
	<!-- 引入js文件 -->
	<!-- jQuery -->
	<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
	<!-- Bootstrap Core JavaScript -->
	<script src="<%=basePath%>js/bootstrap.min.js"></script>
	<!-- Metis Menu Plugin JavaScript -->
	<script src="<%=basePath%>js/metisMenu.min.js"></script>
	<!-- DataTables JavaScript -->
	<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
	<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
	<!-- Custom Theme JavaScript -->
	<script src="<%=basePath%>js/sb-admin-2.js"></script>
	<script charset="UTF-8" language="java" contentType="text/html src="ntkoocx.js"></script>
	<!-- 编写js代码 -->
	<script type="text/javascript">

    //清空新建客户窗口中的数据
	function clearOrders() {
	    $("#new_number").val("");
	    $("#new_cust_id").val("");
	    $("#new_cust_name").val("");
	    $("#new_product_id").val("");
	}
    
	// 创建
	function createOrders() {
	$.post("<%=basePath%>orders/create.action",
	$("#new_orders_form").serialize(),function(data){
	        if(data =="OK"){
	            alert("客户创建成功！");
	            window.location.reload();
	        }else{
	            alert("客户创建失败！");
	            window.location.reload();
	        }
	    });
	}
	
	// 通过id获取修改的信息
	function editOrders(id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>orders/getOrdersById.action",
	        data:{"id":id},
	        success:function(data) {
	        	$("#edit_id").val(data.id);
	            $("#edit_number").val(data.number);
	            $("#edit_cust_id").val(data.cust_id);
	            $("#edit_cust_name").val(data.cust_name);
	            $("#edit_product_id").val(data.product_id);
	        }
	    });
	}
    // 执行修改操作
	function updateOrders() {
		$.post("<%=basePath%>orders/update.action",$("#edit_orders_form").serialize(),function(data){
			if(data =="OK"){
				alert("订单信息更新成功！");
				window.location.reload();
			}else{
				alert("订单信息更新失败！");
				window.location.reload();
			}
		});
	}
	// 删除
	function deleteOrders(id) {
	    if(confirm('确实要删除该客户吗?')) {
	$.post("<%=basePath%>orders/delete.action",{"id":id},
	function(data){
	            if(data =="OK"){
	                alert("客户删除成功！");
	                window.location.reload();
	            }else{
	                alert("删除客户失败！");
	                window.location.reload();
	            }
	        });
	    }
	}
</script>

</body>
</html>